#ifndef __CJOYPAD_LAYER_H
#define __CJOYPAD_LAYER_H

#include "cocos2d.h"
#include "CMyGameDef.h"

using namespace cocos2d;

typedef void (CCObject::*SEL_JoyHandler)(CCObject*, int, int, bool); // this, button type, direction, pressed

#define joypad_btn_selector(_SELECTOR) (SEL_JoyHandler)(&_SELECTOR)


class CJoyPadLayer : public CCLayer
{
public:
	virtual bool init();
	CREATE_FUNC(CJoyPadLayer);
	virtual void registerWithTouchDispatcher(void);
	virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
	virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
	virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
    // a selector callback
    virtual void buttonnCallback(CCObject* pSender);
	void registerEventCallback(CCObject *pTarget, SEL_JoyHandler selector);
	void showJoystickThumb(void);

protected :
	int m_nLastDirect;
	CCObject* m_pListener;
	SEL_JoyHandler m_pfnSelector;
	CCPoint m_pntJoyCenter;
	CCSprite *m_pJoystickThumb;
	int m_nJoystickRadius;
	bool m_bTouchJoystick;
};

#endif // __CJOYPAD_LAYER_H